{% extends "admin/base_site.html" %}
{% load i18n admin_urls admin_static admin_list material_admin %}

{% block extrastyle %}
{{ block.super }}
{{ media.css }}
{% endblock %}


{% block extrajs %}
<script type="text/javascript">
(function($) {
  $(document).ready(function($) {
    if ($('#result_list').length != 0) {
      var table = $("#result_list").DataTable({
        paging: false,
        ordering: false,
        info: false,
        bFilter: false,
        bAutoWidth: false,
        responsive: {
          details: false
        }
      });
      new $.fn.dataTable.FixedHeader(table);
    }

    /*
      Search form
     */
    $('#searchbar').keyup(function (e) {
      if(e.keyCode == 13) {
        $("#searchbar_hidden").attr('name', $('#searchbar').data('name'));
        $("#searchbar_hidden").val($('#searchbar').val());
        $("#changelist-search").submit();
      }
    });
    $("#changelist-search-button").click(function() {
      $("#searchbar_hidden").attr('name', $('#searchbar').data('name'));
      $("#searchbar_hidden").val($('#searchbar').val());
      $("#changelist-search").submit();
    });

    $(".admin_filter").change(function() {
      window.location.href = $(this).val();
    });

    $(".date_hierarchy").change(function() {
      window.location.href = $(this).val();
    });
  });
  })(jQuery);

{% if action_form %}{% if actions_on_top or actions_on_bottom %}
(function($) {
  $(document).ready(function($) {
    $("tr input.action-select").actions();
  });
})(jQuery);
{% endif %}{% endif %}
</script>
{% endblock %}

{% block brand-logo %}{{ cl.opts.verbose_name_plural|title }}{% endblock %}

{% block breadcrumbs_items %}
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
<a class="active" href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
{% endblock %}


{% block main_content %}
<form method="POST" class="content">
    {% csrf_token %}
    <div class="left-panel{% if action_form or cl.date_hierarchy or cl.list_filter or cl.search_fields %}{% else %} wide{% endif %}">
        <div class="card">
            <div class="card-content">
                {% block result_list %}
                {% result_list cl %}
                {% endblock %}
                
                {% block pagination %}{% pagination cl %}{% endblock %}
            </div>
        </div>
    </div>

    {% if action_form or cl.date_hierarchy or cl.list_filter or cl.search_fields %}
    <div class="right-panel">
        {% if action_form and actions_on_top and cl.show_admin_actions %}
        {% admin_actions %}
        {% endif %}
        {% if cl.date_hierarchy or cl.list_filter or cl.search_fields %}
        <div class="card filters-card">
            <div class="card-content">
                <span class="card-title">{% trans 'Filter' %}</span>
                {% block search %}{% search_form cl %}{% endblock %}
                
                {% block filters %}
                {% if cl.has_filters %}
                <div class="changelist-filter row">
                    {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
                </div>
                {% endif %}
                {% endblock %}
                
                {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
                <div class="clearfix"></div>
            </div>
            <div class="card-action">&nbsp;</div>
        </div>
        {% endif %}
    </div>
    {% endif %}
</form>

{% if has_add_permission %}
{% url cl.opts|admin_urlname:'add' as add_url %}
<div class="fixed-action-btn">
    <a class="btn-floating btn-large waves-effect waves-light red z-depth-2" href="{% add_preserved_filters add_url is_popup to_field %}">
        <i class="large material-icons">add</i>
    </a>
</div>
{% endif %}

<form id="changelist-search" action="?" method="get">
    <input type="hidden" id="searchbar_hidden"/>
    {% for pair in cl.params.items %}
    {% ifnotequal pair.0 'q' %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %}
    {% endfor %}
</form>
{% endblock %}
